//
//  HomeTableViewCell.swift
//  HoneyBee
//
//  Created by point on 2018/1/24.
//  Copyright © 2018年 point. All rights reserved.
//

import UIKit

class HomeTableViewCell: UITableViewCell {
    @IBOutlet weak var schoolNameLabel: UILabel!
    @IBOutlet weak var remarkLabel: UILabel!
    @IBOutlet weak var preferential: UILabel!
    @IBOutlet weak var headImg: UIImageView!
    @IBOutlet weak var distanceLabel: UILabel!
    
    @IBOutlet weak var preferentialImageView: UIImageView!
    
    var startView:UILabel = UILabel(name: "⭐️", color: UIColor.white, fontSize: 12)
    var scoreLabel:UILabel = UILabel()
    override func awakeFromNib() {
        super.awakeFromNib()
        selectionStyle = .none
        contentView.addSubview(startView)
        startView.snp.makeConstraints { (make) in
            make.left.equalTo(schoolNameLabel)
            make.bottom.equalToSuperview().inset(5)
        }
        contentView.addSubview(scoreLabel)
        scoreLabel.snp.makeConstraints { (make) in
            make.left.equalTo(startView.snp.right).offset(5)
            make.centerY.equalTo(startView.snp.centerY)
        }
//        scoreLabel.textColor = UIColor.init(hex: <#T##String#>, alpha: <#T##CGFloat#>)
        scoreLabel.font = UIFont.systemFont(ofSize: 14)
        scoreLabel.textColor = UIColor.init(r: 153.0, g: 153.0, b: 153.0)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        headImg.cornerForView(conrners: .allCorners, radius: 4)
    }
    
    func configModel(model:SchoolModel , index:IndexPath)  {
        schoolNameLabel.text = model.name
        remarkLabel.text = model.remark
        preferential.text = model.preferential
        headImg.showImageS(model.headImg)
        distanceLabel.text = model.distance
        preferentialImageView.isHidden = !Bool.init(truncating: NSNumber.init(value: model.preferential.count))
        model.score = 3.4
        scoreLabel.text = String.init(model.score)
        startView.text = Array<String>(repeatElement("⭐️", count: Int(round(Double(model.score))))).joined(separator: " ")
    }
}
